// pages/homePage/homePage.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      partnerUserId: options.partnerUserId
    })
  },
  /**
   * 页面分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: that.data.title,
      desc: '分享页面的内容',
      imageUrl: "http://file.jwsxmall.com/shareImg.jpg",
      path: '/pages/integralMall/integralMall?partnerUserId=' + wx.getStorageSync("userId") + '&type=2', // 路径，传递参数到指定页面
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var that = this;
    wx.request({//获取积分
      url: app.globalData.url + 'getUserByUserId?userId=' + wx.getStorageSync("userId"),
      method: "get",
      success: function (res) {
        var user = res.data.data;
        that.setData({
          points: user.points,
        })
        wx.setStorageSync("points", user.points)
        wx.setStorageSync("points", user.balance)
      }
    })
    that.setData({
      level:wx.getStorageSync("level")
    })
    wx.request({
      url: app.globalData.url + 'getIntegralShoppingMallProduct', //
      data: {
        userId: wx.getStorageSync("userId")
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if (res.data.result==1) {
          that.setData({
            integralProduct: res.data.data
          })
          
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
        } else {
          wx.navigateTo({
            url: '/pages/zcuslist/index?partnerUserId=' + that.data.partnerUserId + '&fan=1'
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  goProductDetails:function(e){
    wx.navigateTo({
      url: '/pages/integralDetail/integralDetail?productId=' + e.currentTarget.dataset.productid,
    })
  },
  navBack: function () {
    wx.switchTab({
      url: '/pages/mallPage/mallPage',
    })
  },
  checkIn:function(){
    wx.navigateTo({
      url: '/pages/checkIn/checkIn',
    })
  },
})